<template>
    <d2-container>
     <!--    <el-form :inline="true" :model="dataSearch" ref="dataSearch">

            <el-form-item label="审批状态" prop="status">
                <el-radio-group v-model="dataSearch.status">
                    <el-radio :label="-1">取消</el-radio>
                    <el-radio :label="0">审批中</el-radio>
                    <el-radio :label="1">审批同意</el-radio>
                    <el-radio :label="2">审批拒绝</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="formSubmit">
                    <d2-icon name="search"/>
                    查询
                </el-button>
            </el-form-item>
            <el-form-item>
                <el-button @click="formReset">
                    <d2-icon name="refresh"/>
                    重置
                </el-button>
            </el-form-item>
        </el-form> -->
        <el-table :data="dataList" border style="width: 100%">
            <el-table-column prop="student.name" label="学生姓名"></el-table-column>
            <el-table-column prop="class.name" label="请假班级"></el-table-column>
            <el-table-column prop="remark" label="请假原因"></el-table-column>
            <el-table-column prop="timeText" label="请假时间"></el-table-column>
            
        </el-table>
        <el-pagination
                background
                layout="total,sizes,prev, pager, next,jumper"
                :page-size="pageSize"
                :current-page="currentPage"
                :total="total"
                @current-change="handleCurrentChange"
                @size-change="handlerSizeChange"
                @next-click="handleNextPage"
                @prev-click="handlePrevClick"
        ></el-pagination>
    </d2-container>
</template>

<script>
    import request from "@/plugin/axios";
        import {mapState} from "vuex"
        import formatTime from '@/libs/util.formatTime'
    export default {

        data() {
            return {
                options:{
                  genderOption:[
                      {
                          label:'男',
                          value:1
                      },
                      {
                          label:'女',
                          value:2
                      },
                      {
                          label:'未设定',
                          value:0
                      }
                  ]
                },
                dataList: [],
                total: 100,
                pageSize: 20,
                currentPage: 1,
                class: [''],
                dataSearch: {},
            };
        },
         computed: {
            ...mapState('d2admin/user', ['info'])
        },
        methods: {
            formSubmit() {
                this.dataSearch.page = this.currentPage;
                this.dataSearch.pageSize = this.pageSize;
                this.getDataList(this.dataSearch);
            },
            formReset() {
                this.$refs.dataSearch.resetFields();
            },
            handleAgreeClick(e) {
                this.$confirm("此操作同意审批通过, 是否继续?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                })
                    .then(() => {
                        request({
                            url: "/studentLeave/updateStudentLeaveList",
                            method: "post",
                            data: { _id: e._id,status:1 }
                        }).then(res => {
                            if (res.code == 200) {
                                this.$message({
                                    message: "操作成功"
                                });
                                this.getDataList(this.dataSearch);
                            }
                        });
                    })
                    .catch(() => {
                        this.$message({
                            type: "info",
                            message: "已取消操作"
                        });
                    });
            },

            handleDisagreeClick(e) {
                this.$confirm("此操作拒绝审批通过, 是否继续?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                })
                    .then(() => {
                        request({
                            url: "/studentLeave/updateStudentLeaveList",
                            method: "post",
                            data: { _id: e._id ,status: 2}
                        }).then(res => {
                            if (res.code == 200) {
                                this.$message({
                                    message: "操作成功"
                                });
                                this.getDataList(this.dataSearch);
                            }
                        });
                    })
                    .catch(() => {
                        this.$message({
                            type: "info",
                            message: "已取消操作"
                        });
                    });
            },

            handleCurrentChange(currentPage) {
                this.currentPage = currentPage
                this.dataSearch.page = this.currentPage;
                this.dataSearch.pageSize = this.pageSize;
                this.getDataList(this.dataSearch);
            },
            handlerSizeChange(pageSize) {
                this.pageSize = pageSize
                this.dataSearch.page = this.currentPage;
                this.dataSearch.pageSize = this.pageSize;
                this.getDataList(this.dataSearch);
            },
            handleNextPage() {
                this.currentPage = this.currentPage + 1
                this.dataSearch.page = this.currentPage;
                this.dataSearch.pageSize = this.pageSize;
                this.getDataList(this.dataSearch);
            },
            handlePrevClick() {
                this.currentPage = this.currentPage - 1
                this.dataSearch.page = this.currentPage;
                this.dataSearch.pageSize = this.pageSize;
                this.getDataList(this.dataSearch);
            },

            getDataList(data) {
                request({
                    url: "/studentLeave/getStudentLeaveList",
                    method: "post",
                    data: data
                }).then(res => {

                    this.dataList = [];
                    this.dataList = res.data.leaveRecord;
                    this.dataList.forEach(e=>{
                        e.timeText = formatTime.formatTime(new Date(e.date))
                    })
                    this.total = res.data.total;
                    this.currentPage = res.data.currentPage;
                })
            }
        },
        created() {
            this.school = this.info.school[0]._id
            this.staff = this.info.staff == undefined ? null : this.info.staff._id
            this.staffname = this.info.staff == undefined ? '' : this.info.staff.name
            this.rights = this.info.rights.map(function(e){return e.name})
            let index1 = this.rights.indexOf('root') == -1
            let index5 = this.rights.indexOf('校长') == -1
            let index2 = this.rights.indexOf('授课老师') != -1
            let index4 = this.rights.indexOf('教务老师') != -1
            index2 = (index2 || index4)
            index1 = index1 || index5
            let index3 = this.rights.indexOf('教务中心') == -1

            if ((index1) && (index2)){
                if (index3){
                    this.teacher = true
                    this.dataSearch.teacher = 1
                    this.dataSearch.staff = this.staff
                }
            }
            this.dataSearch.school = this.school
            this.dataSearch.page = this.currentPage;
            this.dataSearch.pageSize = this.pageSize;
            console.log(this.dataSearch,'sdss','ckxk')
            this.getDataList(this.dataSearch);
        }
    };
</script>
